package fr.m2if.main;

/**
 * Write a description of class Livre here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
/**
 * @author malika
 *
 */
public class Livre
{

	private static long sequence = 0;
    private String nom;
    private String auteur;
    private String collection;
    private long id;
	private boolean disponible;
	
 

    public String getNom() {
		return nom;
	}


	public void setNom(String nom) {
		this.nom = nom;
	}


	public String getAuteur() {
		return auteur;
	}


	public void setAuteur(String auteur) {
		this.auteur = auteur;
	}


	public String getCollection() {
		return collection;
	}


	public void setCollection(String collection) {
		this.collection = collection;
	}


	public long getId() {
		return id;
	}



	public boolean isDisponible() {
		return disponible;
	}


	public void setDisponible(boolean disponible) {
		this.disponible = disponible;
	}


	/**
     * Constructor for objects of class Livre
     */
    public Livre()
    {
    	id=sequence;
    	sequence++;
    	disponible=true;
    }


    public void emprunte() throws Exception{
    	if(disponible){
    		disponible=false;
    	}
    	else throw new Exception("Book not currently available");
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((auteur == null) ? 0 : auteur.hashCode());
		result = prime * result
				+ ((collection == null) ? 0 : collection.hashCode());
		result = prime * result + (disponible ? 1231 : 1237);
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Livre other = (Livre) obj;
		if (auteur == null) {
			if (other.auteur != null)
				return false;
		} else if (!auteur.equals(other.auteur))
			return false;
		if (collection == null) {
			if (other.collection != null)
				return false;
		} else if (!collection.equals(other.collection))
			return false;
		if (disponible != other.disponible)
			return false;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		return true;
	}




}
